#coding:utf-8
from Tkinter import *
import tkMessageBox
import time
import threading

class Application(Frame):
	def __init__(self, master=None):
		Frame.__init__(self, master)
		self.pack()
		self.createWidgets()

	def createWidgets(self):
		#self.nameInput = Entry(self)
		#self.nameInput.pack()
		#self.alertButton = Button(self, text='Hello', command=self.hello)
		#self.alertButton.pack()
		
		self.LabSend = Label(self, text = '发送信息')
		self.LabSend.grid()
		self.LabRecive = Label(self, text = '接收信息')
		self.LabRecive.grid(row = 0, column = 1)
		self.listSend = Listbox(self, width = 50)
		self.listSend.grid(row = 1, column = 0)
		self.listRecive = Listbox(self, width = 50)
		self.listRecive.grid(row = 1, column = 1)
		self.btnStart = Button(self, text='开始', command=self.start)
		self.btnStart.grid(row = 2, column = 0)
		self.btnEnd = Button(self, text='停止', command=self.end, state = DISABLED)
		self.btnEnd.grid(row = 2, column = 1)

	def start(self):
		#name = self.nameInput.get() or 'world'
		#tkMessageBox.showinfo('Message', 'Hello, %s' % name)

		#now_time = time.localtime(time.time())
		#self.listSend.insert(0, "[%s] User %s login" % (time.asctime(now_time), '913106840350'))
		self.btnEnd['state'] = ACTIVE
		self.btnStart['state'] = DISABLED
		t = threading.Thread(target=self.do)
		t.start()

	def end(self):
		pass

	def do(self):
		now_time = time.localtime(time.time())
		self.listSend.insert(0, "[%s] User %s login" % (time.asctime(now_time), '913106840350'))
		time.sleep(5)
		now_time = time.localtime(time.time())
		self.listSend.insert(0, "[%s] User %s login" % (time.asctime(now_time), '913106840350'))
		self.btnEnd['state'] = DISABLED
		self.btnStart['state'] = ACTIVE


app = Application()
# 设置窗口标题:
app.master.title('Hello World')
# 主消息循环:
app.mainloop()